package icu.d4peng.cloud.gateway.service.impl;

import icu.d4peng.cloud.gateway.repository.RouteRepository;
import icu.d4peng.cloud.gateway.service.DynamicRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @author d4peng
 * @version 1.0.0
 * @date 2022-01-04 16:09
 * @description DynamicRouteServiceImpl:动态路由实现
 */
@Service
public class DynamicRouteServiceImpl implements DynamicRouteService {
    private final RouteRepository routeRepository;

    @Autowired
    public DynamicRouteServiceImpl(RouteRepository routeRepository) {
        this.routeRepository = routeRepository;
    }

    @Override
    public Flux<RouteDefinition> routes() {
        return this.routeRepository.getRouteDefinitions();
    }

    @Override
    public Mono<Void> save(Mono<RouteDefinition> route) {
        return this.routeRepository.save(route);
    }

    @Override
    public Mono<Void> delete(Mono<String> routeId) {
        return this.routeRepository.delete(routeId);
    }

}
